package com.tju.vodTest;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;

import java.util.List;

public class TestVod {
    public static void main(String[] args) throws ClientException {
//        String accessKeyId = "LTAI5tNpuS7uvCc378bDU1b6";
//        String accessKeySecret = "HBVlfF8krk8PUD4wZy1DnsWmawqD4l";
//        String title = "wallpaper2"; //上传之后文件的名称
//        String fileName = "C:\\Users\\Administrator.DESKTOP-6FFHHHP\\Videos\\LiveWallpaper\\9e7190f1618185df03628a7120e6be5b\\1635877028195_KrY3D.mp4"; //本地文件的路径和名称
//
//        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
//        /* 可指定分片上传时每个分片的大小，默认为2M字节 */
//        request.setPartSize(2 * 1024 * 1024L);
//        /* 可指定分片上传时的并发线程数，默认为1，(注：该配置会占用服务器CPU资源，需根据服务器情况指定）*/
//        request.setTaskNum(1);
//
//        UploadVideoImpl uploader = new UploadVideoImpl();
//        UploadVideoResponse response = uploader.uploadVideo(request);
//        if (response.isSuccess()) {
//            System.out.print("VideoId=" + response.getVideoId() + "\n"); //获取到上传视频的id
//        } else {
//            /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
//            System.out.print("VideoId=" + response.getVideoId() + "\n");
//            System.out.print("ErrorCode=" + response.getCode() + "\n");
//            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
//        }
        getPlayAuth();

    }

    public static void getPlayUrl() throws ClientException{
        //根据视屏id获取视屏播放地址
        //创建初始化对象
        DefaultAcsClient defaultAcsClient = InitObject.initVodClient("LTAI5tNpuS7uvCc378bDU1b6", "HBVlfF8krk8PUD4wZy1DnsWmawqD4l");

        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();
        request.setVideoId("746eb3a5f52740cb83f0bc6b9877f087");

        response = defaultAcsClient.getAcsResponse(request);

        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");

        }
        //Base信息
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");//VideoBase.Title = 6 - What If I Want to Move Faster.mp4

    }
    //获取播放凭证
    public static void getPlayAuth() throws ClientException {
        DefaultAcsClient defaultAcsClient = InitObject.initVodClient("LTAI5tNpuS7uvCc378bDU1b6", "HBVlfF8krk8PUD4wZy1DnsWmawqD4l");
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        request.setVideoId("94abc61e8c8a484e849632b0f5dbeafd");
        response = defaultAcsClient.getAcsResponse(request);
        System.out.println("播放凭证：" + response.getPlayAuth());
    }
}
